import { GameEventCenter } from "../../GameEventCenter";
import { FuncItemInfo, GlobalObj } from "../../obj/GlobalObj";
import { PGCServer } from "../../PGCServer";
import { GoodsType, LevelData } from "../../uiComp/LevelListComp";
import { DressUpDataParse } from "../DressUpDataParse";
import { MLotteryClothePage } from "../MLotteryClothePage";
import { DressUpData } from "./DressUpData";
import { DressUpTempMgr } from "./DressUpTempMgr";



export class DressUpServerDataMgr {

    /**数据*/
    datas: Map<string, any[]> = new Map();
    /**所有的物品列表*/
    allGoodsMap: Map<number, any[]> = new Map();

    /** avatar tag 数据 */
    avatarTags: string[];

    private _tagMap: Map<string, number>;// tag 标签对应的数据

    public isCache: boolean = false;// 是否开启数据缓存

    private _dressUpTempMgr: DressUpTempMgr;

    _clearDressData: DressUpData;

    private _yanyingDatas: any[];// 用于眼影的通用画法
    private _yanyingGroupDatas: Map<string, any[]>;// 用于眼影多色的通用画法

    // static searchFunc

    static configMgr: ClassifyDataManager;
    private static _ins: DressUpServerDataMgr;
    static get Ins(): DressUpServerDataMgr {
        return this._ins ||= new DressUpServerDataMgr();
    }
    constructor() {
        this._dressUpTempMgr = new DressUpTempMgr();
    }
    getTag(key: any) {
        return this._tagMap.get(key);
    }
    initMap() {

        GameEventCenter.Ins.on(GameEventCenter.CHANGE_MAKE_UP_GOODS, this , this.changeCacheState);

        
        let boneTags = DressUpServerDataMgr.configMgr.getPrefabDataByPrefabType(DressUpServerTag.AVATAR_BONE_TAG);
        let suitTags = DressUpServerDataMgr.configMgr.getPrefabDataByPrefabType(DressUpServerTag.AVATAR_SUIT_TAG);
        let wuguanTags = DressUpServerDataMgr.configMgr.getPrefabDataByPrefabType(DressUpServerTag.WU_GUAN_TAG);
        let zhuangrongTags = DressUpServerDataMgr.configMgr.getPrefabDataByPrefabType(DressUpServerTag.ZHUANG_RONG_TAG);

        this.avatarTags = [];
        this._parseTags(boneTags, DressUpServerTag.AVATAR_BONE_TAG, true);
        this._parseTags(suitTags, DressUpServerTag.AVATAR_SUIT_TAG);
        this._parseTags(wuguanTags, DressUpServerTag.WU_GUAN_TAG);
        this._parseTags(zhuangrongTags, DressUpServerTag.ZHUANG_RONG_TAG);
        console.log("部件tag:", this._tagMap, this.avatarTags);



        let self = this;
        function __addAllGoods(data: any, tag: number) {
            if (data && !data.ret) {
                self.allGoodsMap.set(tag, data.data);
            }
        }

        PGCServer.ins.getDressUpList(DressUpServerTag.AVATAR_BONE_TAG, [], Laya.Handler.create(this, (data: any) => {
            __addAllGoods(data, DressUpServerTag.AVATAR_BONE_TAG);
            console.log("部件数据:" + DressUpServerTag.AVATAR_BONE_TAG, data)
        }));
        PGCServer.ins.getDressUpList(DressUpServerTag.AVATAR_SUIT_TAG, [], Laya.Handler.create(this, (data: any) => {
            __addAllGoods(data, DressUpServerTag.AVATAR_SUIT_TAG);
            console.log("部件数据:" + DressUpServerTag.AVATAR_SUIT_TAG, data)
        }));
        PGCServer.ins.getDressUpList(DressUpServerTag.WU_GUAN_TAG, [], Laya.Handler.create(this, (data: any) => {
            __addAllGoods(data, DressUpServerTag.WU_GUAN_TAG);
            console.log("部件数据:" + DressUpServerTag.WU_GUAN_TAG, data)
        }));
        PGCServer.ins.getDressUpList(DressUpServerTag.ZHUANG_RONG_TAG, [], Laya.Handler.create(this, (data: any) => {
            __addAllGoods(data, DressUpServerTag.ZHUANG_RONG_TAG);
            console.log("部件数据:" + DressUpServerTag.ZHUANG_RONG_TAG, data)
        }));

    }

    /** 是否包含了某个分类 
   * @param key  中文类型 + _ + 大分类的Tag
  */
    containTagByKey(key: string, ids: string | number[]): boolean {
        if (!ids) return false;
        let id = this._tagMap.get(key);
        if (typeof ids == "string") {
            return ids.split(",").indexOf(id + "") >= 0;
        } else {
            return ids.indexOf(id) >= 0;
        }
    }

    gettagMap(data: any, index: number = 1) {
        var value = 0
        if (data.system_tag_ids && data.system_tag_ids.length > 0) {
            value = data.system_tag_ids[index];
        }
        this.tempdata = "";
        this._tagMap.forEach((element, key) => {
            if (element == value) {
                this.tempdata = key;
            }
        });
        var str = this.tempdata.split("_");
        if (str.length > 0) {
            return str[0].trim();
        }
        return "";
    }


    private _parseTags(tags: any[], type: number, isBone?: boolean) {
        let alias: any[];
        this._tagMap ||= new Map();
        let aliasKey: string, tag: number;
        for (let index = 0; index < tags.length; index++) {
            const tagObj = tags[index];
            alias = tagObj.alias;
            if (alias) {
                for (const key in alias) {
                    aliasKey = alias[key].tag_name + "_" + type;
                    tag = parseInt(key);
                    this._tagMap.set(aliasKey, tag);
                    if (isBone) {
                        this.avatarTags[tag] = alias[key].tag_name;
                    }
                }
            }
        }
    }


    /**
     * @param levelData 选中标签
     * @param isdoubleList 是否是颜色和画法类型
     * @param callback 
     */
    getTabListArr(levelData: LevelData<FuncItemInfo>, isdoubleList: boolean, callback: Laya.Handler): void {
        let levelName = levelData.type;
        let prelevelName = levelData.preNode.type;
        let pprelevelName = levelData.preNode.preNode && levelData.preNode.preNode.type;
        let tag: number;
        let isClothe = prelevelName == GoodsType.WU_GUAN && levelName == GoodsType.W_HAT;
        if (prelevelName == GoodsType.FU_SHI || isClothe) { // 服饰
            tag = DressUpServerTag.AVATAR_BONE_TAG;
        } else if (prelevelName == GoodsType.WU_GUAN) { // 五官
            tag = DressUpServerTag.WU_GUAN_TAG;
        } else if (prelevelName == GoodsType.ZHUANG_RONG || pprelevelName == GoodsType.ZHUANG_RONG) { // 妆容
            tag = DressUpServerTag.ZHUANG_RONG_TAG;
        } else { // 套装  和 作品  用其他接口实现
            if (levelName == GoodsType.TAO_ZHUANG) { // 套装
                this.getTabToSuitListArr(levelData, isdoubleList, callback);
            } else { // 作品

                this.getTabToTempListArr(levelData, isdoubleList, callback);
            }
            return;
        }

        let tagKey = this.getTagKey(levelName, tag);
        let tagId = this._tagMap.get(tagKey);

        let preTypeId: number;
        if (prelevelName == GoodsType.Z_KOU_HONG || prelevelName == GoodsType.Z_YAN_YING) {
            preTypeId = this._tagMap.get(prelevelName + "_" + tag);
        }

        if (this.isCache && this.datas.has(tagKey)) // 使用缓存数据
        {
            let doubleList = this.datas.get(tagKey);
            doubleList[0] = this._addClearDressItem(doubleList[0], levelData)
            return callback && callback.runWith([doubleList]);
        }

        let sex = GlobalObj.isFa() ? "女" : "男";
        if (prelevelName == GoodsType.FU_SHI) {
            sex = GlobalObj.isFa() ? "女" : "男";
        }
        sex += "_" + tag;

        let sexId = this._tagMap.get(sex);  // 性别
        let allId = this._tagMap.get("可男可女_" + tag); // 中性


        let searchIds = preTypeId ? [preTypeId] : [tagId]; // 需要搜索的标签
        if (prelevelName == GoodsType.FU_SHI || isClothe) {
            searchIds = [tagId, sexId];
        }
        if(levelName == GoodsType.Z_MEI_MAO){
            isdoubleList = true;
        }
        PGCServer.ins.getDressUpList(tag, searchIds, Laya.Handler.create(this, (data: any) => {
            if (!data.ret && data.data) {
                data.data = (<Array<any>>data.data).filter(
                    (item: any) => item.system_tag_ids.indexOf(allId) >= 0 || item.system_tag_ids.indexOf(sexId) >= 0
                );
                this._parseDressUpTabs(tag, isdoubleList, levelData, data.data);
                this._updateDressUpDatas(data.data, levelData);
                let doubleList = this.datas.get(tagKey);
       
                this._sortListDatas(levelData, doubleList, 0); // 只排序妆容颜色 和 不需要画法的数据
                this._sortDefaultName(doubleList[0], levelData);
                this._sortDefaultName(doubleList[1], levelData);
                this._sortDaBaiBing(doubleList[0], levelData);
                doubleList[0] = this._addClearDressItem(doubleList[0], levelData);
                callback && callback.runWith([doubleList]);
            }
        }));
    }

    /** 妆容颜色暂时不需要，只用素材数据，素材数据颜色不传给可明 */
    private _addDefaultColor(arr: DressUpData[], levelData: LevelData<FuncItemInfo>){
        if ([levelData.type, levelData.preNode.type, levelData.preNode.preNode.type].indexOf(GoodsType.ZHUANG_RONG) == -1) {
            return arr;
        }
        if(levelData.type == GoodsType.Z_XIU_RONG){
            let colors = ['rgba()','rgba()']
            for (let index = 0; index < arr.length; index++) {
                const item = arr[index];
                item.isColor = true;
                item.color = [colors[index]];
            }
        }
    }

    /** 添加不使用的清理按钮 */
    private _addClearDressItem(arr: DressUpData[], levelData: LevelData<FuncItemInfo>): DressUpData[] {
        if ([levelData.type, levelData.preNode.type, levelData.preNode.preNode.type].indexOf(GoodsType.ZHUANG_RONG) == -1) {
            return arr;
        }
        if (!this._clearDressData) {
            this._clearDressData = new DressUpData();
            this._clearDressData.preform_id = -1;
        }
        if(arr[0] && arr[0].preform_id == -1){
            return arr;
        }
        return [this._clearDressData].concat(arr);
    }

    /** 将带默认这两个文字的 妆容排到前排第一位 */
    private _sortDefaultName(arr: DressUpData[], levelData: LevelData<FuncItemInfo>) {
        let isWuguan = levelData.type == GoodsType.WU_GUAN || levelData.preNode.type == GoodsType.WU_GUAN;
        if (isWuguan && arr && arr.length) {
            let findIdx: number;
            for (let index = 0; index < arr.length; index++) {
                const item = arr[index];
                if (item.preform_name.indexOf("默认") >= 0) {
                    findIdx = index;
                    break;
                }
            }
            if (findIdx >= 0) {
                let temp = arr[findIdx];
                arr[findIdx] = arr[0];
                arr[0] = temp;
            }
        }
    }

    private _sortDaBaiBing(arr: DressUpData[], levelData: LevelData<FuncItemInfo>){
        if(levelData.type == GoodsType.Z_DING_ZHUANG){
            if(arr){
                
                let idx = arr.findIndex(item=>item.preform_name == "轻透蜜粉饼");
                if(idx >= 0){
                    let temp = arr[idx];
                    arr[idx] = arr[0];
                    arr[0] = temp;
                }
            }
        }
    }

    /** 根据能否使用排序 */
    private _sortListDatas(levelData: LevelData<FuncItemInfo>, arr: any[], idx: number) {
        
        let sortArr = arr[idx]
        if (this._isMakeUp(levelData)) {
            sortArr = arr[idx].sort((v1: DressUpData, v2: DressUpData) => {
                var i1 = this._sortFunc(v1) ? 1 : 0;
                var i2 = this._sortFunc(v2) ? 1 : 0;
                return i2 - i1;
            });
        }
    }

    /** 是否是妆容 */
    private _isMakeUp(levelData:LevelData<FuncItemInfo>){
        let pretype = levelData.preNode.type;
        let p_pretype = levelData.preNode.preNode.type;
        return pretype == GoodsType.ZHUANG_RONG || p_pretype == GoodsType.ZHUANG_RONG;
    }

    private _sortFunc(curdressUpData: DressUpData): boolean {
        if (!curdressUpData) return false;
        if (GlobalObj.dressState == 2 && curdressUpData.new_user_free == 1) { // 新用户解锁
            return true;
        }
        if (!curdressUpData.goods_info || !curdressUpData.goods_info.goods_ids || !curdressUpData.goods_info.goods_ids.length) {
            return false;
        }
        return true
    }

    private _parseDressUpTabs(tag: number, isdoubleList: boolean, levelData: LevelData<FuncItemInfo>, data: any[]) {

        let prelevelName = levelData.preNode.type;
        let curTabId: number;

        if (prelevelName == GoodsType.Z_KOU_HONG) { // 口红特殊处理，口红画法全部通用

            let childs: LevelData<FuncItemInfo>[] = levelData.preNode.nextNodes;
            for (let index = 0; index < childs.length; index++) {
                const child = childs[index];
                curTabId = this._tagMap.get(this.getTagKey(child.type, tag));
                this._parseKouHong(isdoubleList, tag, curTabId, data, child, true);
            }
        } else if (prelevelName == GoodsType.Z_YAN_YING) { // 眼影需要查询通用的画法放入

            let childs: LevelData<FuncItemInfo>[] = levelData.preNode.nextNodes;
            if (!this._yanyingGroupDatas) {
                this._yanyingGroupDatas = new Map();
            }
            this._yanyingGroupDatas.clear();
            for (let index = 0; index < childs.length; index++) {
                const child = childs[index];
                curTabId = this._tagMap.get(this.getTagKey(child.type, tag));
                this._parseYanYing(isdoubleList, tag, curTabId, data, child, true);
            }
        } else {
            curTabId = this._tagMap.get(this.getTagKey(levelData.type, tag));
            this._parseSigleTab(isdoubleList, tag, curTabId, data, levelData, false);
        }
    }

    private _updateDressUpDatas(newDress: DressUpData | DressUpData[], levelData:LevelData<FuncItemInfo>) {
        if(!this._isMakeUp(levelData))return; // 非妆容不更新
        let dressArr = this.allGoodsMap.get(DressUpServerTag.ZHUANG_RONG_TAG);
        if (!dressArr || !newDress) {
            console.warn("_updateDressUpDatas 妆容数据还没初始化",newDress);
            return;
        }
        function __replaceDress(rDress: DressUpData, dressArr:any[]) {
            let idx = dressArr.findIndex(item => item.preform_id == rDress.preform_id);
            if (idx >= 0) {
                dressArr[idx] = rDress; // 更新数据
            } else {
                console.warn("没找到数据:" + rDress.preform_id);
            }
        }
        if (newDress instanceof Array) {
            for (let index = 0; index < newDress.length; index++) {
                const dress = newDress[index];
                __replaceDress(dress, dressArr);
            }
        } else {
            __replaceDress(newDress, dressArr);
        }
    }

    /** 获取map key.
     * @param levelName GoodsType
     * @param tag 标签
     */
    public getTagKey(levelName: string, tag: number): string {
        let names = levelName.split("_"); // 用于同类名称 加上了前缀区分的情况 ，比如睫毛  在五官和妆容里面都有
        levelName = names[names.length - 1];

        return levelName + "_" + tag;
    }

    public _parseKouHong(isdoubleList: boolean, tag: number, curTabId: number, data: any[], levelData: LevelData<FuncItemInfo>, isDoubleTab: boolean) {
        let levelName = levelData.type;
        let tagKey = this.getTagKey(levelName, tag)
        let doubleList: any[] = [[], []];
        let colorId = this._tagMap.get("颜色" + "_" + tag);
        let realDatas: any[] = data;

        if (isdoubleList) {
            let isColor = false;
            for (let index = 0; index < realDatas.length; index++) {
                const item = realDatas[index];
                let ids = item.system_tag_ids;
                isColor = ids.indexOf(colorId) >= 0;
                if (isColor && ids.indexOf(curTabId) >= 0) {
                    doubleList[0].push(item);
                    item.isColor = true;
                } else if (!isColor && ((ids.length > 3 && ids.indexOf(curTabId) >= 0) || ids.length <= 3)) {
                    doubleList[1].push(item);
                } else {
                    // console.log("剔除的数据:"+item.preform_id);
                }
            }
        } else if (realDatas.length) {
            doubleList[0] = realDatas;
        }
        this.datas.set(tagKey, doubleList);
    }

    public _parseYanYing(isdoubleList: boolean, tag: number, curTabId: number, data: any[], levelData: LevelData<FuncItemInfo>, isDoubleTab: boolean) {
        let levelName = levelData.type;
        let tagKey = this.getTagKey(levelName, tag)
        let doubleList: any[] = [[], []];
        let colorId = this._tagMap.get("颜色" + "_" + tag);
        let realDatas: any[] = data;

        if (isdoubleList) {
            let isColor = false;
            if (!this._yanyingDatas) {
                this._yanyingDatas = [];
            }

            this._yanyingDatas.length = 0;
            for (let index = 0; index < realDatas.length; index++) {
                const item = realDatas[index];
                isColor = item.system_tag_ids.indexOf(colorId) >= 0;
                if (isColor && item.system_tag_ids.indexOf(curTabId) >= 0) {
                    doubleList[0].push(item);
                    item.isColor = true;
                } else if (!isColor && item.system_tag_ids.indexOf(curTabId) >= 0) {
                    doubleList[1].push(item);
                } else {
                    // console.log("剔除的数据:"+item.preform_id);
                }
                if (!isColor && item.system_tag_ids.length <= 3) {
                    this._yanyingDatas.push(item);
                }
            }
            DressUpDataParse.loadArrJson(this._yanyingDatas, null);

            this._yanyingGroupDatas.set(levelData.type, doubleList[1]);
        } else if (realDatas.length) {
            doubleList[0] = realDatas;
        }

        this.datas.set(tagKey, doubleList);
    }

    /** 选中的data */
    public getYanyingDatas(data: DressUpData, levelData: LevelData<FuncItemInfo>): any[] {
        let levelName = levelData.type;
        if (data.color.length > 1) { // 选中了多色颜色
            return this._yanyingGroupDatas.get(levelName);
        } else {
            return this._yanyingDatas;
        }
    }

    /** 选中的data 
     * @param type 1:选中了多颜色的数据 0:单色数据
    */
    public getYanyingDataByType(type: number, levelName: string): any[] {
        if (type) { // 选中了多色颜色
            return this._yanyingGroupDatas.get(levelName);
        } else {
            return this._yanyingDatas;
        }
    }


    /**
     * 解析单个标签
     * @param isdoubleList 是多个list
     * @param tag 大标签分类
     * @param curTabId 当前分类子标签
     * @param data 数据list
     * @param levelData 选中标签
     * @param isDoubleTab 是否是多个标签
     */
    private _parseSigleTab(isdoubleList: boolean, tag: number, curTabId: number, data: any[], levelData: LevelData<FuncItemInfo>, isDoubleTab: boolean) {
        let levelName = levelData.type;
        let tagKey = this.getTagKey(levelName, tag)
        let doubleList: any[] = [[], []];
        let colorId = this._tagMap.get("颜色" + "_" + tag);
        let realDatas: any[] = data;
        // if(isDoubleTab){
        //     realDatas = data.filter(
        //         (item: any) => item.system_tag_ids.indexOf(curTabId) >= 0
        //     );
        // }

        if (isdoubleList) {
            let isColor = false;
            for (let index = 0; index < realDatas.length; index++) {
                const item = realDatas[index];
                isColor = item.system_tag_ids.indexOf(colorId) >= 0;
                if (isColor && item.system_tag_ids.indexOf(curTabId) >= 0) {
                    doubleList[0].push(item);
                    item.isColor = true;
                } else if (!isColor) {
                    doubleList[1].push(item);
                } else {
                    // console.log("剔除的数据:"+item.preform_id);
                }
            }
        } else if (realDatas.length) {
            doubleList[0] = realDatas;
        }

        this.datas.set(tagKey, doubleList);
    }


    getTabToSuitListArr(levelData: LevelData<FuncItemInfo>, isdoubleList: boolean, callback: Laya.Handler) {
        MLotteryClothePage.Ins.getListSuitLuckyBox(Laya.Handler.create(this, (data: any) => {
            callback && callback.runWith([[data, []]]);
        }));
    }

    getListGoodsInSuitLuckyBox(id: number, callback: Laya.Handler) {
        MLotteryClothePage.Ins.getListGoodsInSuitLuckyBox(id, callback);
    }

    getTabToTempListArr(levelData: LevelData<FuncItemInfo>, isdoubleList: boolean, callback: Laya.Handler) {
        this._dressUpTempMgr.getNextPageData(Laya.Handler.create(this, (datas: any[]) => {
            callback && callback.runWith([[datas, []]]);
        }));
    }

    /** 获取 tab list data数据 */
    public getTempTabListData(dressData: DressUpData): any[] {
        let allGroupDressUp: any[] = []
        if (dressData && dressData.developer_avatar_json) {

            let avatarObj = JSON.parse(dressData.developer_avatar_json);
            let temp: any;

            if (avatarObj[0] && avatarObj[0].shopId == -1) {
                if (avatarObj[0].dressUp) {

                    let dressUpDatas = this.allGoodsMap.get(DressUpServerTag.ZHUANG_RONG_TAG);
                    let dressUp = avatarObj[0].dressUp, shopId: number;
                    for (const key in dressUp) {
                        shopId = dressUp[key];

                        temp = dressUpDatas.find(item => item.preform_id == shopId);
                        if (temp) {
                            allGroupDressUp.push(temp);
                        } else {
                            console.log("没有找到妆容数据:" + shopId);
                        }
                    }
                } else {
                    console.log(" 没有妆容数据----------------");
                }
            }

            let boneDatas = this.allGoodsMap.get(DressUpServerTag.AVATAR_BONE_TAG);
            if (boneDatas) {
                for (const key in avatarObj) {
                    if (!isNaN(parseInt(key))) {
                        let bone = avatarObj[key];
                        if (bone) {
                            temp = boneDatas.find(item => item.preform_id == bone.shopId);
                            if (temp) {
                                allGroupDressUp.push(temp);
                            } else {
                                console.log("没有找到部件数据:" + bone);
                            }
                        }
                    }
                }
            } else {
                console.log("没有部件物品数据");
            }

        }
        return allGroupDressUp;
    }

    /** 获取显示数据 */
    getDressUpJson(goodsData: DressUpData, callback: Laya.Handler) {
        if (goodsData.isColor) {
            if (goodsData.color) {
                return callback && callback.runWith(goodsData);
            }
        } else if (goodsData.preform_info) {
            return callback && callback.runWith(goodsData);
        }
        if (!goodsData.preform_file || goodsData.preform_file.indexOf(".dat") >= 0) {// 如果不存在file文件 或者file文件是dat 就不加载
            return callback && callback.runWith(goodsData);
        }
        let url = PGCServer.ins.formatUrl(goodsData.preform_file);
        Laya.loader.load(url, Laya.Handler.create(this, (data: any) => {
            if (data && data.data) {
                if (data.data.colors && data.data.colors.length) {
                    goodsData.isColor = true;// 是颜色
                }
                if (goodsData.isColor) {
                    goodsData.color = data.data.colors;
                }
                let idx = url.lastIndexOf("/");
                goodsData.preform_info ||= {};
                for (const key in data.data) {
                    if (key == "albedoTexture" || key == "dataFile" || key == "maskTexture") { // 资源路径
                        goodsData.preform_info[key] = url.substring(0, idx) + "/" + data.data[key];
                    } else {
                        goodsData.preform_info[key] = data.data[key];
                        if (key !== "colors")
                            console.warn("出现了新字段:----->" + key, data.data[key]);
                    }
                }
            }
            callback && callback.runWith(goodsData);
        }), null, Laya.Loader.JSON);
    }



    public tempdata: any
    getDressUpDataById(id: number) {
        this.tempdata = null;
        this.allGoodsMap.forEach(element => {
            if (element) {
                var data = element.find((v) => v.preform_id == id);
                if (data) {
                    this.tempdata = data;
                }
            }
        });
        return this.tempdata;
    }
    getDressUpDataByGoodsId(id: number) {
        this.tempdata = null;
        this.allGoodsMap.forEach(element => {
            if (element) {
                var data = element.find((v) => v.goods_define_id == id);
                if (data) {
                    this.tempdata = data;
                }
            }
        });
        return this.tempdata;
    }


    canUse(curdressUpData: any, levelData?: LevelData<FuncItemInfo>, data?: any) {
        if (!curdressUpData) return false;
        if (!data || curdressUpData.preform_id != data.preform_id) {
            var huafatag = this._tagMap.get("形状_" + DressUpServerTag.ZHUANG_RONG_TAG);
            if (curdressUpData.system_tag_ids && curdressUpData.system_tag_ids.indexOf(huafatag) >= 0) {
                return true;
            }
        }
        if (GlobalObj.dressState == 2 && curdressUpData.new_user_free == 1) { // 新用户解锁
            return true;
        }
        while (levelData) {
            if ([GoodsType.WU_GUAN, GoodsType.FU_SHI, GoodsType.ZUO_PIN, GoodsType.TAO_ZHUANG].indexOf(levelData.type) >= 0) return true;
            levelData = levelData.preNode;
        }

        if (!curdressUpData.goods_info || !curdressUpData.goods_info.goods_ids || !curdressUpData.goods_info.goods_ids.length) {
            return false;
        }
        return true
    }

    changeCacheState(isCache:boolean){
        this.isCache = isCache;
    }

    public existTemp(callback: Laya.Handler) {
        return this._dressUpTempMgr.existTemp(callback);
    }

    public clear() {
        GameEventCenter.Ins.off(GameEventCenter.CHANGE_MAKE_UP_GOODS, this , this.changeCacheState);
        this.datas.clear();
    }
}

export enum DressUpServerTag {
    /** 套装 */
    AVATAR_SUIT_TAG = 69,
    /** 部件 */
    AVATAR_BONE_TAG = 68,
    /** 五官 */
    WU_GUAN_TAG = 103,
    /** 妆容 */
    ZHUANG_RONG_TAG = 104,
}